home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 24 / Printing Compressed Images / JPEG Print with Dataload / PrintJPEG with dataload.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-03  |  3.3 KB  |  123 lines  |  [TEXT/MPCC]

  1. #ifndef __PRINTJPEG__
  2. #define __PRINTJPEG__
  3.  
  4. #include <ImageCompression.h>
  5.  
  6. struct JPEGImage {
  7.     short    theRefNum;                        /* a file reference number for this image data */
  8.     Rect    theBounds;                        /* the Bounds of the Image */    
  9.     ImageDescriptionHandle theDesc;            /* an ImageDescriptionHandle */
  10. };
  11. typedef struct JPEGImage JPEGImage;
  12.  
  13. #define kMYBUFFERSIZE     (codecMinimumDataSize)
  14.  
  15. // a structure for use in our data loading function
  16. struct DataLoad {
  17.     Handle    theDataBufferH;                    /* a handle to the data buffer */
  18.     short    theRefNum;                        /* a file reference number for the file to read */
  19.     long    theBufferSize;                    /* the length of our data buffer */
  20. };
  21. typedef struct DataLoad DataLoad, *DataLoadPtr;
  22.  
  23.  
  24. // macro for determining if the port is a color port.
  25. #define ISCOLORPORT(gPort) (((gPort)->portBits.rowBytes & 0x8000) != 0)
  26.  
  27.  
  28. /*
  29.     JPEG Marker code definitions.    
  30. */
  31. #define    MARKER_PREFIX    0xff
  32. #define    MARKER_SOI        0xd8        /* start of image */
  33. #define    MARKER_SOF        0xc0        /* start of frame codes */
  34. #define    MARKER_DHT        0xc4        /* define Huffman table */
  35. #define    MARKER_EOI        0xd9        /* end of image */
  36. #define    MARKER_SOS        0xda        /* start of scan */
  37. #define    MARKER_DQT        0xdb        /* define quantization tables */
  38. #define    MARKER_DNL        0xdc        /* define quantization tables */
  39. #define    MARKER_DRI        0xdd        /* define Huffman table */
  40. #define    MARKER_COM        0xfe        /* comment */
  41. #define MARKER_APP0        0xe0        
  42.  
  43.  
  44. //=====================================================================================
  45. // Public interface function prototypes
  46. //=====================================================================================
  47.  
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51.  
  52. static OSErr SetJPEGBounds(JPEGImage * theJPEGImage);
  53.  
  54. static OSErr MakeJPEGImageDescription(JPEGImage *theJPEGImage);
  55.  
  56. static char *
  57. MarkerDetect(char *data,short *width,short *height,long *hRes,long *vRes,short *depth);
  58.  
  59. static void SwallowQuantTable(char *data);
  60.  
  61. static void SwallowHuffTable(char *data);
  62.  
  63. static OSErr DrawJPEGImage(JPEGImage theJPEGImage, Boolean isColorPort);
  64.  
  65. SInt16 main(void);
  66. static OSErr initMacintosh(void);
  67. static OSErr SetupMenus(void);
  68. static SInt16 handleEvent(void);
  69. static OSErr Print(JPEGImage theJPEGImage, THPrint aPrintRecordHandle);
  70. static void DoKeyDown(EventRecord *);
  71. static void doCommand(SInt16,SInt16);
  72. static void showAboutMeDialog(void) ;
  73. static void DoTheOpenCommand(void);
  74. static pascal OSErr MyDataLoadingProc(Ptr *dataP, long bytesNeeded, long refcon);
  75.  
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79.  
  80. /*
  81.  * Resource ID constants.
  82. */
  83. #define kAppleMenuID     128   /* This identifies the apple menu*/
  84. #define kFileMenuID        129
  85. #define kEditMenuID        130
  86.  
  87. // Apple Menu Item Numbers 
  88. #define kAboutMeCommand  1 
  89.  
  90. // File Menu Item Numbers 
  91. #define kOpenCommand        1
  92. #define kSaveCommand        2
  93. // separator line            3
  94. #define kPageSetupCommand    4
  95. #define kPrintCommand        5
  96. // separator line            6
  97. #define kQuitCommand        7
  98.  
  99. /*
  100.  * Support for the About Dialog
  101. */
  102. #define    kAboutMeDLOG        128
  103. #define    kOKButton            1
  104.  
  105. // alert dialog ID to report problems to users.
  106. #define kGenericError         128
  107.  
  108. // define for flags value for calls to StdPix bottleneck.
  109. #define kCallOldBits        (1 << 0)  
  110. #define kCallStdBits        (1 << 1)  
  111.  
  112. #define MIN(x,y)  ( x  >  y  ) ?  y  :  x 
  113.  
  114. #define kSleepTime  5
  115. #define kInsetBits     10
  116.  
  117. // Application Specific Errors
  118. #define kAppError             4017
  119. #define iNotJPEGData         4019
  120. #define kCouldntLoadMenu     4020
  121.  
  122. #endif
  123.